﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;


namespace AnyOffice.general.calendar.manage
{
    public partial class _new : ModulePage
    {
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DateTime time = (Request.QueryString["date"] != null) ? DateTime.Parse(Request.QueryString["date"].ToString()) : DateTime.Now;
                this.ViewState["SpecifyDate"] = time.ToString("yyyy-MM-dd");
                this.litSpecifyDate.Text = time.ToString("yyyy年M月d日");
                this.ckbMobile.Visible = SmsDao.IsMobile(SmsDao.SmsType.Calendar);
            }
            if (this.Page.IsPostBack)
            {
                CalendarDao dao = new CalendarDao();
                CalendarData data = new CalendarData();
                data.StartTime = DateTime.Parse(this.ViewState["SpecifyDate"].ToString() + " " + this.ddlStartHour.SelectedValue + ":" + this.ddlStartMinute.SelectedValue);
                data.EndTime = DateTime.Parse(this.ViewState["SpecifyDate"].ToString() + " " + this.ddlEndHour.SelectedValue + ":" + this.ddlEndMinute.SelectedValue);
                data.UserId = base.User.Identity.Name;
                data.Content = this.txtContent.Value;
                data.CalType = Convert.ToInt32(this.selectCalType.Value);
                int num = dao.Insert(base.Conn, data);
                if (this.ckbSms.Checked || this.ckbMobile.Checked)
                {
                    SmsDao dao2 = new SmsDao();
                    SmsData data2 = new SmsData();
                    data2.FromId = base.User.Identity.Name;
                    data2.ToId = base.User.Identity.Name;
                    data2.Type = 5;
                    data2.SendTime = DateTime.Parse(this.ViewState["SpecifyDate"].ToString() + " " + this.ddlStartHour.SelectedValue + ":" + this.ddlStartMinute.SelectedValue);
                    data2.Content = "请查看日程安排!\n内容:" + this.txtContent.Value;
                    data2.RelateId = num;
                    dao2.BizSend(base.Conn, data2, this.ckbSms.Checked, this.ckbMobile.Checked);
                }
                base.CloseConn();
                Response.Redirect("manage.aspx?date=" + this.ViewState["SpecifyDate"].ToString());
            }
        } 

    }
}
